<?php
	/**
	 * This is a MetaControl class, providing a QForm or QPanel access to event handlers
	 * and QControls to perform the Create, Edit, and Delete functionality
	 * of the Librarydetails class.  This code-generated class
	 * contains all the basic elements to help a QPanel or QForm display an HTML form that can
	 * manipulate a single Librarydetails object.
	 *
	 * To take advantage of some (or all) of these control objects, you
	 * must create a new QForm or QPanel which instantiates a LibrarydetailsMetaControl
	 * class.
	 *
	 * Any and all changes to this file will be overwritten with any subsequent
	 * code re-generation.
	 * 
	 * @package My Application
	 * @subpackage MetaControls
	 * property-read Librarydetails $Librarydetails the actual Librarydetails data class being edited
	 * property QLabel $IdControl
	 * property-read QLabel $IdLabel
	 * property QTextBox $LibraryNameControl
	 * property-read QLabel $LibraryNameLabel
	 * property QTextBox $SummaryOfLibraryControl
	 * property-read QLabel $SummaryOfLibraryLabel
	 * property QIntegerTextBox $CreatorControl
	 * property-read QLabel $CreatorLabel
	 * property QListBox $MemberdetailsAsLibraryMemberControl
	 * property-read QLabel $MemberdetailsAsLibraryMemberLabel
	 * property-read string $TitleVerb a verb indicating whether or not this is being edited or created
	 * property-read boolean $EditMode a boolean indicating whether or not this is being edited or created
	 */

	class LibrarydetailsMetaControlGen extends QBaseClass {
		// General Variables
		protected $objLibrarydetails;
		protected $objParentObject;
		protected $strTitleVerb;
		protected $blnEditMode;

		// Controls that allow the editing of Librarydetails's individual data fields
		protected $lblId;
		protected $txtLibraryName;
		protected $txtSummaryOfLibrary;
		protected $txtCreator;

		// Controls that allow the viewing of Librarydetails's individual data fields
		protected $lblLibraryName;
		protected $lblSummaryOfLibrary;
		protected $lblCreator;

		// QListBox Controls (if applicable) to edit Unique ReverseReferences and ManyToMany References
		protected $lstMemberdetailsesAsLibraryMember;

		// QLabel Controls (if applicable) to view Unique ReverseReferences and ManyToMany References
		protected $lblMemberdetailsesAsLibraryMember;


		/**
		 * Main constructor.  Constructor OR static create methods are designed to be called in either
		 * a parent QPanel or the main QForm when wanting to create a
		 * LibrarydetailsMetaControl to edit a single Librarydetails object within the
		 * QPanel or QForm.
		 *
		 * This constructor takes in a single Librarydetails object, while any of the static
		 * create methods below can be used to construct based off of individual PK ID(s).
		 *
		 * @param mixed $objParentObject QForm or QPanel which will be using this LibrarydetailsMetaControl
		 * @param Librarydetails $objLibrarydetails new or existing Librarydetails object
		 */
		 public function __construct($objParentObject, Librarydetails $objLibrarydetails) {
			// Setup Parent Object (e.g. QForm or QPanel which will be using this LibrarydetailsMetaControl)
			$this->objParentObject = $objParentObject;

			// Setup linked Librarydetails object
			$this->objLibrarydetails = $objLibrarydetails;

			// Figure out if we're Editing or Creating New
			if ($this->objLibrarydetails->__Restored) {
				$this->strTitleVerb = QApplication::Translate('Edit');
				$this->blnEditMode = true;
			} else {
				$this->strTitleVerb = QApplication::Translate('Create');
				$this->blnEditMode = false;
			}
		 }

		/**
		 * Static Helper Method to Create using PK arguments
		 * You must pass in the PK arguments on an object to load, or leave it blank to create a new one.
		 * If you want to load via QueryString or PathInfo, use the CreateFromQueryString or CreateFromPathInfo
		 * static helper methods.  Finally, specify a CreateType to define whether or not we are only allowed to 
		 * edit, or if we are also allowed to create a new one, etc.
		 * 
		 * @param mixed $objParentObject QForm or QPanel which will be using this LibrarydetailsMetaControl
		 * @param integer $intId primary key value
		 * @param QMetaControlCreateType $intCreateType rules governing Librarydetails object creation - defaults to CreateOrEdit
 		 * @return LibrarydetailsMetaControl
		 */
		public static function Create($objParentObject, $intId = null, $intCreateType = QMetaControlCreateType::CreateOrEdit) {
			// Attempt to Load from PK Arguments
			if (strlen($intId)) {
				$objLibrarydetails = Librarydetails::Load($intId);

				// Librarydetails was found -- return it!
				if ($objLibrarydetails)
					return new LibrarydetailsMetaControl($objParentObject, $objLibrarydetails);

				// If CreateOnRecordNotFound not specified, throw an exception
				else if ($intCreateType != QMetaControlCreateType::CreateOnRecordNotFound)
					throw new QCallerException('Could not find a Librarydetails object with PK arguments: ' . $intId);

			// If EditOnly is specified, throw an exception
			} else if ($intCreateType == QMetaControlCreateType::EditOnly)
				throw new QCallerException('No PK arguments specified');

			// If we are here, then we need to create a new record
			return new LibrarydetailsMetaControl($objParentObject, new Librarydetails());
		}

		/**
		 * Static Helper Method to Create using PathInfo arguments
		 *
		 * @param mixed $objParentObject QForm or QPanel which will be using this LibrarydetailsMetaControl
		 * @param QMetaControlCreateType $intCreateType rules governing Librarydetails object creation - defaults to CreateOrEdit
		 * @return LibrarydetailsMetaControl
		 */
		public static function CreateFromPathInfo($objParentObject, $intCreateType = QMetaControlCreateType::CreateOrEdit) {
			$intId = QApplication::PathInfo(0);
			return LibrarydetailsMetaControl::Create($objParentObject, $intId, $intCreateType);
		}

		/**
		 * Static Helper Method to Create using QueryString arguments
		 *
		 * @param mixed $objParentObject QForm or QPanel which will be using this LibrarydetailsMetaControl
		 * @param QMetaControlCreateType $intCreateType rules governing Librarydetails object creation - defaults to CreateOrEdit
		 * @return LibrarydetailsMetaControl
		 */
		public static function CreateFromQueryString($objParentObject, $intCreateType = QMetaControlCreateType::CreateOrEdit) {
			$intId = QApplication::QueryString('intId');
			return LibrarydetailsMetaControl::Create($objParentObject, $intId, $intCreateType);
		}



		///////////////////////////////////////////////
		// PUBLIC CREATE and REFRESH METHODS
		///////////////////////////////////////////////

		/**
		 * Create and setup QLabel lblId
		 * @param string $strControlId optional ControlId to use
		 * @return QLabel
		 */
		public function lblId_Create($strControlId = null) {
			$this->lblId = new QLabel($this->objParentObject, $strControlId);
			$this->lblId->Name = QApplication::Translate('Id');
			if ($this->blnEditMode)
				$this->lblId->Text = $this->objLibrarydetails->Id;
			else
				$this->lblId->Text = 'N/A';
			return $this->lblId;
		}

		/**
		 * Create and setup QTextBox txtLibraryName
		 * @param string $strControlId optional ControlId to use
		 * @return QTextBox
		 */
		public function txtLibraryName_Create($strControlId = null) {
			$this->txtLibraryName = new QTextBox($this->objParentObject, $strControlId);
			$this->txtLibraryName->Name = QApplication::Translate('Library Name');
			$this->txtLibraryName->Text = $this->objLibrarydetails->LibraryName;
			$this->txtLibraryName->MaxLength = Librarydetails::LibraryNameMaxLength;
			return $this->txtLibraryName;
		}

		/**
		 * Create and setup QLabel lblLibraryName
		 * @param string $strControlId optional ControlId to use
		 * @return QLabel
		 */
		public function lblLibraryName_Create($strControlId = null) {
			$this->lblLibraryName = new QLabel($this->objParentObject, $strControlId);
			$this->lblLibraryName->Name = QApplication::Translate('Library Name');
			$this->lblLibraryName->Text = $this->objLibrarydetails->LibraryName;
			return $this->lblLibraryName;
		}

		/**
		 * Create and setup QTextBox txtSummaryOfLibrary
		 * @param string $strControlId optional ControlId to use
		 * @return QTextBox
		 */
		public function txtSummaryOfLibrary_Create($strControlId = null) {
			$this->txtSummaryOfLibrary = new QTextBox($this->objParentObject, $strControlId);
			$this->txtSummaryOfLibrary->Name = QApplication::Translate('Summary Of Library');
			$this->txtSummaryOfLibrary->Text = $this->objLibrarydetails->SummaryOfLibrary;
			$this->txtSummaryOfLibrary->TextMode = QTextMode::MultiLine;
			return $this->txtSummaryOfLibrary;
		}

		/**
		 * Create and setup QLabel lblSummaryOfLibrary
		 * @param string $strControlId optional ControlId to use
		 * @return QLabel
		 */
		public function lblSummaryOfLibrary_Create($strControlId = null) {
			$this->lblSummaryOfLibrary = new QLabel($this->objParentObject, $strControlId);
			$this->lblSummaryOfLibrary->Name = QApplication::Translate('Summary Of Library');
			$this->lblSummaryOfLibrary->Text = $this->objLibrarydetails->SummaryOfLibrary;
			return $this->lblSummaryOfLibrary;
		}

		/**
		 * Create and setup QIntegerTextBox txtCreator
		 * @param string $strControlId optional ControlId to use
		 * @return QIntegerTextBox
		 */
		public function txtCreator_Create($strControlId = null) {
			$this->txtCreator = new QIntegerTextBox($this->objParentObject, $strControlId);
			$this->txtCreator->Name = QApplication::Translate('Creator');
			$this->txtCreator->Text = $this->objLibrarydetails->Creator;
			return $this->txtCreator;
		}

		/**
		 * Create and setup QLabel lblCreator
		 * @param string $strControlId optional ControlId to use
		 * @param string $strFormat optional sprintf format to use
		 * @return QLabel
		 */
		public function lblCreator_Create($strControlId = null, $strFormat = null) {
			$this->lblCreator = new QLabel($this->objParentObject, $strControlId);
			$this->lblCreator->Name = QApplication::Translate('Creator');
			$this->lblCreator->Text = $this->objLibrarydetails->Creator;
			$this->lblCreator->Format = $strFormat;
			return $this->lblCreator;
		}

		/**
		 * Create and setup QListBox lstMemberdetailsesAsLibraryMember
		 * @param string $strControlId optional ControlId to use
		 * @return QListBox
		 */
		public function lstMemberdetailsesAsLibraryMember_Create($strControlId = null) {
			$this->lstMemberdetailsesAsLibraryMember = new QListBox($this->objParentObject, $strControlId);
			$this->lstMemberdetailsesAsLibraryMember->Name = QApplication::Translate('Memberdetailses As Library Member');
			$this->lstMemberdetailsesAsLibraryMember->SelectionMode = QSelectionMode::Multiple;
			$objAssociatedArray = $this->objLibrarydetails->GetMemberdetailsAsLibraryMemberArray();
			$objMemberdetailsArray = Memberdetails::LoadAll();
			if ($objMemberdetailsArray) foreach ($objMemberdetailsArray as $objMemberdetails) {
				$objListItem = new QListItem($objMemberdetails->__toString(), $objMemberdetails->Id);
				foreach ($objAssociatedArray as $objAssociated) {
					if ($objAssociated->Id == $objMemberdetails->Id)
						$objListItem->Selected = true;
				}
				$this->lstMemberdetailsesAsLibraryMember->AddItem($objListItem);
			}
			return $this->lstMemberdetailsesAsLibraryMember;
		}

		/**
		 * Create and setup QLabel lblMemberdetailsesAsLibraryMember
		 * @param string $strControlId optional ControlId to use
		 * @param string $strGlue glue to display in between each associated object
		 * @return QLabel
		 */
		public function lblMemberdetailsesAsLibraryMember_Create($strControlId = null, $strGlue = ', ') {
			$this->lblMemberdetailsesAsLibraryMember = new QLabel($this->objParentObject, $strControlId);
			$this->lblMemberdetailsesAsLibraryMember->Name = QApplication::Translate('Memberdetailses As Library Member');
			
			$objAssociatedArray = $this->objLibrarydetails->GetMemberdetailsAsLibraryMemberArray();
			$strItems = array();
			foreach ($objAssociatedArray as $objAssociated)
				$strItems[] = $objAssociated->__toString();
			$this->lblMemberdetailsesAsLibraryMember->Text = implode($strGlue, $strItems);
			return $this->lblMemberdetailsesAsLibraryMember;
		}




		/**
		 * Refresh this MetaControl with Data from the local Librarydetails object.
		 * @param boolean $blnReload reload Librarydetails from the database
		 * @return void
		 */
		public function Refresh($blnReload = false) {
			if ($blnReload)
				$this->objLibrarydetails->Reload();

			if ($this->lblId) if ($this->blnEditMode) $this->lblId->Text = $this->objLibrarydetails->Id;

			if ($this->txtLibraryName) $this->txtLibraryName->Text = $this->objLibrarydetails->LibraryName;
			if ($this->lblLibraryName) $this->lblLibraryName->Text = $this->objLibrarydetails->LibraryName;

			if ($this->txtSummaryOfLibrary) $this->txtSummaryOfLibrary->Text = $this->objLibrarydetails->SummaryOfLibrary;
			if ($this->lblSummaryOfLibrary) $this->lblSummaryOfLibrary->Text = $this->objLibrarydetails->SummaryOfLibrary;

			if ($this->txtCreator) $this->txtCreator->Text = $this->objLibrarydetails->Creator;
			if ($this->lblCreator) $this->lblCreator->Text = $this->objLibrarydetails->Creator;

			if ($this->lstMemberdetailsesAsLibraryMember) {
				$this->lstMemberdetailsesAsLibraryMember->RemoveAllItems();
				$objAssociatedArray = $this->objLibrarydetails->GetMemberdetailsAsLibraryMemberArray();
				$objMemberdetailsArray = Memberdetails::LoadAll();
				if ($objMemberdetailsArray) foreach ($objMemberdetailsArray as $objMemberdetails) {
					$objListItem = new QListItem($objMemberdetails->__toString(), $objMemberdetails->Id);
					foreach ($objAssociatedArray as $objAssociated) {
						if ($objAssociated->Id == $objMemberdetails->Id)
							$objListItem->Selected = true;
					}
					$this->lstMemberdetailsesAsLibraryMember->AddItem($objListItem);
				}
			}
			if ($this->lblMemberdetailsesAsLibraryMember) {
				$objAssociatedArray = $this->objLibrarydetails->GetMemberdetailsAsLibraryMemberArray();
				$strItems = array();
				foreach ($objAssociatedArray as $objAssociated)
					$strItems[] = $objAssociated->__toString();
				$this->lblMemberdetailsesAsLibraryMember->Text = implode($strGlue, $strItems);
			}

		}



		///////////////////////////////////////////////
		// PROTECTED UPDATE METHODS for ManyToManyReferences (if any)
		///////////////////////////////////////////////

		protected function lstMemberdetailsesAsLibraryMember_Update() {
			if ($this->lstMemberdetailsesAsLibraryMember) {
				$this->objLibrarydetails->UnassociateAllMemberdetailsesAsLibraryMember();
				$objSelectedListItems = $this->lstMemberdetailsesAsLibraryMember->SelectedItems;
				if ($objSelectedListItems) foreach ($objSelectedListItems as $objListItem) {
					$this->objLibrarydetails->AssociateMemberdetailsAsLibraryMember(Memberdetails::Load($objListItem->Value));
				}
			}
		}





		///////////////////////////////////////////////
		// PUBLIC LIBRARYDETAILS OBJECT MANIPULATORS
		///////////////////////////////////////////////

		/**
		 * This will save this object's Librarydetails instance,
		 * updating only the fields which have had a control created for it.
		 */
		public function SaveLibrarydetails() {
			try {
				// Update any fields for controls that have been created
				if ($this->txtLibraryName) $this->objLibrarydetails->LibraryName = $this->txtLibraryName->Text;
				if ($this->txtSummaryOfLibrary) $this->objLibrarydetails->SummaryOfLibrary = $this->txtSummaryOfLibrary->Text;
				if ($this->txtCreator) $this->objLibrarydetails->Creator = $this->txtCreator->Text;

				// Update any UniqueReverseReferences (if any) for controls that have been created for it

				// Save the Librarydetails object
				$this->objLibrarydetails->Save();

				// Finally, update any ManyToManyReferences (if any)
				$this->lstMemberdetailsesAsLibraryMember_Update();
			} catch (QCallerException $objExc) {
				$objExc->IncrementOffset();
				throw $objExc;
			}
		}

		/**
		 * This will DELETE this object's Librarydetails instance from the database.
		 * It will also unassociate itself from any ManyToManyReferences.
		 */
		public function DeleteLibrarydetails() {
			$this->objLibrarydetails->UnassociateAllMemberdetailsesAsLibraryMember();
			$this->objLibrarydetails->Delete();
		}		



		///////////////////////////////////////////////
		// PUBLIC GETTERS and SETTERS
		///////////////////////////////////////////////

		/**
		 * Override method to perform a property "Get"
		 * This will get the value of $strName
		 *
		 * @param string $strName Name of the property to get
		 * @return mixed
		 */
		public function __get($strName) {
			switch ($strName) {
				// General MetaControlVariables
				case 'Librarydetails': return $this->objLibrarydetails;
				case 'TitleVerb': return $this->strTitleVerb;
				case 'EditMode': return $this->blnEditMode;

				// Controls that point to Librarydetails fields -- will be created dynamically if not yet created
				case 'IdControl':
					if (!$this->lblId) return $this->lblId_Create();
					return $this->lblId;
				case 'IdLabel':
					if (!$this->lblId) return $this->lblId_Create();
					return $this->lblId;
				case 'LibraryNameControl':
					if (!$this->txtLibraryName) return $this->txtLibraryName_Create();
					return $this->txtLibraryName;
				case 'LibraryNameLabel':
					if (!$this->lblLibraryName) return $this->lblLibraryName_Create();
					return $this->lblLibraryName;
				case 'SummaryOfLibraryControl':
					if (!$this->txtSummaryOfLibrary) return $this->txtSummaryOfLibrary_Create();
					return $this->txtSummaryOfLibrary;
				case 'SummaryOfLibraryLabel':
					if (!$this->lblSummaryOfLibrary) return $this->lblSummaryOfLibrary_Create();
					return $this->lblSummaryOfLibrary;
				case 'CreatorControl':
					if (!$this->txtCreator) return $this->txtCreator_Create();
					return $this->txtCreator;
				case 'CreatorLabel':
					if (!$this->lblCreator) return $this->lblCreator_Create();
					return $this->lblCreator;
				case 'MemberdetailsAsLibraryMemberControl':
					if (!$this->lstMemberdetailsesAsLibraryMember) return $this->lstMemberdetailsesAsLibraryMember_Create();
					return $this->lstMemberdetailsesAsLibraryMember;
				case 'MemberdetailsAsLibraryMemberLabel':
					if (!$this->lblMemberdetailsesAsLibraryMember) return $this->lblMemberdetailsesAsLibraryMember_Create();
					return $this->lblMemberdetailsesAsLibraryMember;
				default:
					try {
						return parent::__get($strName);
					} catch (QCallerException $objExc) {
						$objExc->IncrementOffset();
						throw $objExc;
					}
			}
		}

		/**
		 * Override method to perform a property "Set"
		 * This will set the property $strName to be $mixValue
		 *
		 * @param string $strName Name of the property to set
		 * @param string $mixValue New value of the property
		 * @return mixed
		 */
		public function __set($strName, $mixValue) {
			try {
				switch ($strName) {
					// Controls that point to Librarydetails fields
					case 'IdControl':
						return ($this->lblId = QType::Cast($mixValue, 'QControl'));
					case 'LibraryNameControl':
						return ($this->txtLibraryName = QType::Cast($mixValue, 'QControl'));
					case 'SummaryOfLibraryControl':
						return ($this->txtSummaryOfLibrary = QType::Cast($mixValue, 'QControl'));
					case 'CreatorControl':
						return ($this->txtCreator = QType::Cast($mixValue, 'QControl'));
					case 'MemberdetailsAsLibraryMemberControl':
						return ($this->lstMemberdetailsesAsLibraryMember = QType::Cast($mixValue, 'QControl'));
					default:
						return parent::__set($strName, $mixValue);
				}
			} catch (QCallerException $objExc) {
				$objExc->IncrementOffset();
				throw $objExc;
			}
		}
	}
?>